package com.czkj.hwz.decorate.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.czkj.hwz.decorate.R;

import java.util.List;

/**
 * Created by Administrator on 2017/9/27.
 */

public class RecycleAdapter extends RecyclerView.Adapter<RecycleAdapter.ViewHolder> {
    private List<String> mList;

    public RecycleAdapter(List<String> list) {
        mList = list;
        notifyDataSetChanged();
    }
    public void updateData(List<String> list) {
        this.mList = list;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //实例化展示的view
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_company, parent, false);
        //实例化viewholder
        ViewHolder viewHolder=new ViewHolder(v);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv_company.setText(mList.get(position));
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView tv_company;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_company = (TextView) itemView.findViewById(R.id.tv_company);
        }
    }

}
